package com.whq.thrift.api.web.base.serviceconf.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.base.serviceconf.db.ModuleInfo;
import com.whq.thrift.api.web.base.serviceconf.db.ModuleInfoMapper;
import com.whq.thrift.api.web.base.serviceconf.service.ModuleInfoService;

@Service
public class ModuleInfoServiceImpl implements ModuleInfoService {
	@Autowired
    private ModuleInfoMapper moduleInfoMapper;

	public void addRecord(ModuleInfo record) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		if (record == null) {
			return ;
		}
		Date now  = new Date();
		record.setCreateTime(now);
		record.setUpdateTime(now);
		
		this.moduleInfoMapper.addRecord(record);
	}

	public List<ModuleInfo> findRecordsByMap(String moduleId, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		
//		if (whereParams == null) {
//			whereParams = new HashMap<String, Object>(0);
//		}
//		whereParams.put("beginIndex", beginIndex);
//		whereParams.put("maxCount", maxCount);
		return this.moduleInfoMapper.findRecordsByMap(moduleId, beginIndex, maxCount);
	}

	public void updateRecord(ModuleInfo record) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		if (record == null) {
			return ;
		}
		Date now  = new Date();
		record.setUpdateTime(now);
		
		this.moduleInfoMapper.updRecord(record);
	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		
		this.moduleInfoMapper.delRecord(id);
	}

	public int findRecordCount(String moduleId) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		
		return this.moduleInfoMapper.findRecordsCount(moduleId);
	}

	public ModuleInfo findRecordById(String id) {
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		
		return this.moduleInfoMapper.getRecordByKey(id);
	}
	
	public List<ModuleInfo> findIsGateWayRecords(int isGateWay, int moduleStatus){
		DataSourceContextHolder.set("dataSourceBaseServiceConfig");
		
		return this.moduleInfoMapper.findIsGateWayRecords(isGateWay, moduleStatus);
	}

}